import sqlite3

def init_db():
    conn = sqlite3.connect('data/students.db')
    cursor = conn.cursor()

    # 创建表
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS users (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            username TEXT NOT NULL,
            password TEXT NOT NULL
        )
    ''')
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS students (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            name TEXT NOT NULL,
            email TEXT NOT NULL
        )
    ''')

    # 插入数据
    cursor.executemany('''
        INSERT INTO user (username, password) VALUES (?, ?)
    ''', [
        ('admin', 'admin123'),
        ('teacher', 'teach456')
    ])

    cursor.executemany('''
        INSERT INTO student (name, email) VALUES (?, ?)
    ''', [
        ('Alice Johnson', 'alice.johnson@example.com'),
        ('Bob Smith', 'bob.smith@example.com'),
        ('Carol Davis', 'carol.davis@example.com')
    ])

    conn.commit()
    conn.close()
    print("Database initialized successfully.")

if __name__ == '__main__':
    init_db()
